Library & Dataset

Using OLR

Inspect Dataset Using Training and Validation

OLR Equations

Inspect Dataset Using Training and Validation

vclust <- varclus (~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil +  TC_weath_rock  + TC_unstable_structure  + T_construction  + spring +  landfill + garbage  + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank  + tree + ground_veg + deforestation + banana + drainage , data=train.data)

# took out density since training has 0 d4 and it was not allowing do the plot

p <- plot(vclust)

par(mfrow=c(6,5))
plot.xmean.ordinaly (risk~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil +  TC_weath_rock  + TC_unstable_structure  + T_construction  + spring +  landfill + garbage  + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank  + tree + ground_veg + deforestation + banana + drainage, data=train.data, cr=TRUE , subn=FALSE)

#angle + building+density+EN +TC + TC_mature_Soil + TC_saprolito +  TC_weath_rock + TC_rock + TC_geol_desfav + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + DepTaludeAterro + aterro + lixo + entulho + crack + belly_wall + scars + drawback + tilted + fracture + conc_rainfall_water + wastewater + leak + septic_tank + drainage + tree + ground_veg + deforestation + banana 

Diagnostic 2: Proportion (-5% of one of the parameters based on what is expected. Since some parameters have 2 predictors, others 5)

#library(plyr)
brick <- count(train.data$brick) %>% 
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "brick")

wood <- count(train.data$wood) %>% 
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "wood")

mixed <- count(train.data$mixed) %>% 
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "mixed")

TC_mature_soil <- count(train.data$TC_mature_soil) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_mature_soil")

T_construction  <- count(train.data$T_construction ) %>%
  mutate ("Percentage"=(freq/265)*100) %>%
  mutate("Classifier" = "T_construction ")

spring <- count(train.data$spring) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "spring")

landfill <- count(train.data$landfill) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "landfill")

garbage <- count(train.data$garbage) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "garbage")

crack <- count(train.data$crack) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "crack")

leaning_wall <- count(train.data$leaning_wall) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "leaning_wall")

scars <- count(train.data$scars) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "DepTaludeAterro")

downward_floor <- count(train.data$downward_floor) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "scars")

tilted <- count(train.data$tilted) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "tilted")

conc_rainfall <- count(train.data$conc_rainfall) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "conc_rainfall")

wastewater <- count(train.data$wastewater) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "wastewater")

leak <- count(train.data$leak) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "conc_rainfall_water")

septic_tank <- count(train.data$septic_tank) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "septic_tank")

angle <- count(train.data$angle) # angle A less than 5% but the rest are okay (3,50, 91, 277, 109) Expected=106
angle <- angle %>%
  mutate("Percentage"=(freq/106)*100)%>%
  mutate("Classifier" = "angle")

EN <- count(train.data$EN) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "EN")

TC <- count(train.data$TC)  %>%
  mutate ("Percentage"=(freq/265)*100) %>%
  mutate("Classifier" = "TC")

TC_saprolite_soil  <- count(train.data$TC_saprolite_soil )  %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_saprolite_soil ")

banana <- count(train.data$banana) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "banana")

drainage <- count(train.data$drainage) %>%
  mutate ("Percentage"=(freq/176.7)*100)%>%
  mutate("Classifier" = "drainage")

deforestation <- count(train.data$deforestation) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "deforestation")

TC_unstable_structure  <- count(train.data$TC_unstable_structure ) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_unstable_structure ")


tree <- count(train.data$tree) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "tree")

ground_veg <- count(train.data$ground_veg) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "ground_veg")


density <- count(train.data$density)  %>% #(79, 415, 36) # d4 =0 
  mutate ("Percentage"=(freq/132.5)*100)%>%
  mutate("Classifier" = "density")

TC_weath_rock  <- count(train.data$TC_weath_rock ) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_weath_rock ")

fracture <- count(train.data$fracture) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "fracture")









df <- rbind(brick, wood, mixed, TC_mature_soil, T_construction, spring, landfill, garbage, crack, leaning_wall, scars, downward_floor, tilted, conc_rainfall, wastewater, leak, septic_tank, angle, EN, TC, TC_saprolite_soil,  banana, drainage, deforestation, TC_unstable_structure, tree, ground_veg,density, TC_weath_rock, fracture)

df
##        x freq  Percentage             Classifier
## 1  FALSE   35  13.2075472                  brick
## 2   TRUE  495 186.7924528                  brick
## 3  FALSE  458 172.8301887                   wood
## 4   TRUE   72  27.1698113                   wood
## 5  FALSE  489 184.5283019                  mixed
## 6   TRUE   41  15.4716981                  mixed
## 7  FALSE  244  92.0754717         TC_mature_soil
## 8   TRUE  286 107.9245283         TC_mature_soil
## 9  FALSE  197  74.3396226        T_construction 
## 10  TRUE  333 125.6603774        T_construction 
## 11 FALSE  515 194.3396226                 spring
## 12  TRUE   15   5.6603774                 spring
## 13 FALSE  326 123.0188679               landfill
## 14  TRUE  204  76.9811321               landfill
## 15 FALSE  332 125.2830189                garbage
## 16  TRUE  198  74.7169811                garbage
## 17 FALSE  439 165.6603774                  crack
## 18  TRUE   91  34.3396226                  crack
## 19 FALSE  503 189.8113208           leaning_wall
## 20  TRUE   27  10.1886792           leaning_wall
## 21 FALSE  321 121.1320755        DepTaludeAterro
## 22  TRUE  209  78.8679245        DepTaludeAterro
## 23 FALSE  470 177.3584906                  scars
## 24  TRUE   60  22.6415094                  scars
## 25 FALSE  429 161.8867925                 tilted
## 26  TRUE  101  38.1132075                 tilted
## 27 FALSE   17   6.4150943          conc_rainfall
## 28  TRUE  513 193.5849057          conc_rainfall
## 29 FALSE  210  79.2452830             wastewater
## 30  TRUE  320 120.7547170             wastewater
## 31 FALSE  348 131.3207547    conc_rainfall_water
## 32  TRUE  182  68.6792453    conc_rainfall_water
## 33 FALSE  525 198.1132075            septic_tank
## 34  TRUE    5   1.8867925            septic_tank
## 35     C   34  32.0754717                  angle
## 36     D  120 113.2075472                  angle
## 37     E  376 354.7169811                  angle
## 38 FALSE  346 130.5660377                     EN
## 39  TRUE  184  69.4339623                     EN
## 40 FALSE   25   9.4339623                     TC
## 41  TRUE  505 190.5660377                     TC
## 42 FALSE  445 167.9245283     TC_saprolite_soil 
## 43  TRUE   85  32.0754717     TC_saprolite_soil 
## 44 FALSE  359 135.4716981                 banana
## 45  TRUE  171  64.5283019                 banana
## 46     Y   66  37.3514431               drainage
## 47     P  235 132.9937748               drainage
## 48     N  229 129.5981890               drainage
## 49 FALSE  492 185.6603774          deforestation
## 50  TRUE   38  14.3396226          deforestation
## 51 FALSE  513 193.5849057 TC_unstable_structure 
## 52  TRUE   17   6.4150943 TC_unstable_structure 
## 53 FALSE  215  81.1320755                   tree
## 54  TRUE  315 118.8679245                   tree
## 55 FALSE  163  61.5094340             ground_veg
## 56  TRUE  367 138.4905660             ground_veg
## 57    d1   58  43.7735849                density
## 58    d2  441 332.8301887                density
## 59    d3   31  23.3962264                density
## 60 FALSE  520 196.2264151         TC_weath_rock 
## 61  TRUE   10   3.7735849         TC_weath_rock 
## 62 FALSE  529 199.6226415               fracture
## 63  TRUE    1   0.3773585               fracture

TC_weath_rock, TC_rock_TC_geol_desf, fracture, TC_rock

Equation 1

f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana , data=train.data, x=TRUE , y=TRUE)

f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana + septic_tank +TC_mature_Soil , data=train.data, x=TRUE , y=TRUE) print (f1 , latex =TRUE , coefs =5) stargazer(anova(f1), type=“text”, style=“default”)

# Equation 1

eq_OLR_01 <- polr(risk ~ brick+ wood+ EN +  TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil, data= train.data
           ,  method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_01))



p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                            Value Std. Error    t value      p value
## brickTRUE             -1.2390663  0.4613852 -2.6855353 3.620686e-03
## woodTRUE               1.0071461  0.3268982  3.0809164 1.031823e-03
## ENTRUE                 0.4768801  0.3580960  1.3317103 9.147770e-02
## TC_mature_soilTRUE     0.5497335  0.2233394  2.4614271 6.919276e-03
## T_constructionTRUE     0.3108695  0.3708859  0.8381810 2.009645e-01
## springTRUE            -0.5769465  0.6805492 -0.8477660 1.982841e-01
## landfillTRUE           0.4254165  0.3278022  1.2977843 9.718073e-02
## leakTRUE              -0.3205059  0.2427776 -1.3201628 9.339033e-02
## garbageTRUE            0.2616029  0.2924380  0.8945586 1.855116e-01
## crackTRUE              1.6927245  0.3261907  5.1893704 1.055032e-07
## leaning_wallTRUE       1.5950203  0.5392333  2.9579409 1.548507e-03
## scarsTRUE              4.1897938  0.3788602 11.0589441 9.920981e-29
## downward_floorTRUE     1.1338038  0.3748885  3.0243762 1.245732e-03
## tiltedTRUE             0.9646526  0.3135689  3.0763657 1.047703e-03
## septic_tankTRUE        0.4330775  1.0461477  0.4139736 3.394467e-01
## conc_rainfallTRUE      1.6363234  0.5570323  2.9375735 1.653959e-03
## wastewaterTRUE         0.9372871  0.2440191  3.8410392 6.125728e-05
## ground_vegTRUE         0.8658041  0.2583794  3.3509023 4.027435e-04
## angleD                 0.7153446  0.4670190  1.5317249 6.279517e-02
## angleE                 0.6761471  0.5288539  1.2785139 1.005341e-01
## TC_saprolite_soilTRUE  0.1763019  0.2933702  0.6009537 2.739354e-01
## R1|R2                  0.6364662  0.8916385  0.7138164 2.376703e-01
## R2|R3                  5.0268331  0.9458544  5.3145951 5.344736e-08
## R3|R4                 10.3248355  1.0610976  9.7303351 1.119271e-22
stargazer((ctable), type="text", style="default", digits = 2)
## 
## ======================================================
##                       Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE             -1.24    0.46     -2.69   0.004 
## woodTRUE              1.01     0.33     3.08    0.001 
## ENTRUE                0.48     0.36     1.33    0.09  
## TC_mature_soilTRUE    0.55     0.22     2.46    0.01  
## T_constructionTRUE    0.31     0.37     0.84    0.20  
## springTRUE            -0.58    0.68     -0.85   0.20  
## landfillTRUE          0.43     0.33     1.30    0.10  
## leakTRUE              -0.32    0.24     -1.32   0.09  
## garbageTRUE           0.26     0.29     0.89    0.19  
## crackTRUE             1.69     0.33     5.19   0.0000 
## leaning_wallTRUE      1.60     0.54     2.96    0.002 
## scarsTRUE             4.19     0.38     11.06     0   
## downward_floorTRUE    1.13     0.37     3.02    0.001 
## tiltedTRUE            0.96     0.31     3.08    0.001 
## septic_tankTRUE       0.43     1.05     0.41    0.34  
## conc_rainfallTRUE     1.64     0.56     2.94    0.002 
## wastewaterTRUE        0.94     0.24     3.84   0.0001 
## ground_vegTRUE        0.87     0.26     3.35   0.0004 
## angleD                0.72     0.47     1.53    0.06  
## angleE                0.68     0.53     1.28    0.10  
## TC_saprolite_soilTRUE 0.18     0.29     0.60    0.27  
## R1| R2                0.64     0.89     0.71    0.24  
## R2| R3                5.03     0.95     5.31   0.0000 
## R3| R4                10.32    1.06     9.73      0   
## ------------------------------------------------------

less p-value = 0.10 (TC_saprolitoTRUE,TaterroTRUE, DepTaludeAterroTRUE,DepTaludeAterroTRUE,landfillTRUE, construction_depositTRUE, leakTRUE)

par(mfrow=c(5,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN +  TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
          ,data=train.data, cr=TRUE , subn=FALSE ,  cex.lab=1.5, cex.axis=2, cex.sub=2, cex.main=2)

Creating function with four level

Equation 1

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN +  TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +-----------------+---+---+----+----------+------------+----------+
## |                 |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +-----------------+---+---+----+----------+------------+----------+
## |brick            |No | 35|Inf | 3.5263605| 1.575536361|-0.5260931|
## |                 |Yes|494|Inf | 2.2761518|-0.097242548|-2.0771662|
## +-----------------+---+---+----+----------+------------+----------+
## |wood             |No |457|Inf | 2.2392580|-0.153473402|-2.2143609|
## |                 |Yes| 72|Inf | 3.1354942| 1.025852934|-0.7563261|
## +-----------------+---+---+----+----------+------------+----------+
## |EN               |No |345|Inf | 1.9229206|-0.417557154|-2.3884464|
## |                 |Yes|184|Inf | 4.0998847| 0.801135819|-1.3131721|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_mature_soil   |No |244|Inf | 1.8908504|-0.263814591|-2.2155737|
## |                 |Yes|285|Inf | 2.8903718| 0.218407947|-1.7006073|
## +-----------------+---+---+----+----------+------------+----------+
## |T_construction   |No |197|Inf | 1.4978854|-0.999521386|-4.1692459|
## |                 |Yes|332|Inf | 3.3735459| 0.556067588|-1.4128614|
## +-----------------+---+---+----+----------+------------+----------+
## |spring           |No |514|Inf | 2.2961817|-0.023347364|-2.0237526|
## |                 |Yes| 15|Inf |       Inf| 0.693147181| 0.1335314|
## +-----------------+---+---+----+----------+------------+----------+
## |landfill         |No |325|Inf | 1.8281271|-0.522329448|-2.8364760|
## |                 |Yes|204|Inf | 4.6151205| 0.851970766|-1.1249296|
## +-----------------+---+---+----+----------+------------+----------+
## |leak             |No |347|Inf | 1.9826422|-0.296092551|-2.4329866|
## |                 |Yes|182|Inf | 3.5667118| 0.563935449|-1.2669476|
## +-----------------+---+---+----+----------+------------+----------+
## |garbage          |No |332|Inf | 2.0166110|-0.328216256|-2.5978471|
## |                 |Yes|197|Inf | 3.1623055| 0.551647618|-1.2172180|
## +-----------------+---+---+----+----------+------------+----------+
## |crack            |No |438|Inf | 2.1671471|-0.350579054|-2.7227563|
## |                 |Yes| 91|Inf | 3.7954892| 2.339399066|-0.1984509|
## +-----------------+---+---+----+----------+------------+----------+
## |leaning_wall     |No |502|Inf | 2.2701498|-0.087705580|-2.1367310|
## |                 |Yes| 27|Inf |       Inf| 2.079441542| 0.2231436|
## +-----------------+---+---+----+----------+------------+----------+
## |scars            |No |320|Inf | 1.7844867|-1.445954198|-4.3694479|
## |                 |Yes|209|Inf | 5.3375381| 3.521446510|-0.8178507|
## +-----------------+---+---+----+----------+------------+----------+
## |downward_floor   |No |469|Inf | 2.1948577|-0.244277863|-2.2187308|
## |                 |Yes| 60|Inf |       Inf| 3.367295830|-0.5465437|
## +-----------------+---+---+----+----------+------------+----------+
## |tilted           |No |428|Inf | 2.1167792|-0.417161148|-2.3877429|
## |                 |Yes|101|Inf | 4.6051702| 2.597384633|-0.7683706|
## +-----------------+---+---+----+----------+------------+----------+
## |septic_tank      |No |524|Inf | 2.3173689|-0.007633625|-1.9372144|
## |                 |Yes|  5|Inf |       Inf| 0.405465108|-0.4054651|
## +-----------------+---+---+----+----------+------------+----------+
## |conc_rainfall    |No | 17|Inf |-0.3566749|-2.772588722|      -Inf|
## |                 |Yes|512|Inf | 2.5523969| 0.054701136|-1.8763169|
## +-----------------+---+---+----+----------+------------+----------+
## |wastewater       |No |210|Inf | 1.6094379|-0.465363250|-2.8954096|
## |                 |Yes|319|Inf | 3.2419411| 0.296831267|-1.5252932|
## +-----------------+---+---+----+----------+------------+----------+
## |ground_veg       |No |163|Inf | 1.3710269|-1.371026889|-2.8397280|
## |                 |Yes|366|Inf | 3.2245738| 0.537142932|-1.6493103|
## +-----------------+---+---+----+----------+------------+----------+
## |angle            |C  | 34|Inf |       Inf|-0.356674944|-3.4965076|
## |                 |D  |120|Inf | 3.3672958| 0.927986772|-1.1895841|
## |                 |E  |375|Inf | 2.0439349|-0.251991706|-2.1535495|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_saprolite_soil|No |444|Inf | 2.2072749|-0.099180320|-2.0419840|
## |                 |Yes| 85|Inf | 3.3081070| 0.504556011|-1.3862944|
## +-----------------+---+---+----+----------+------------+----------+
## |Overall          |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +-----------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=1, cex.sub=1)

Equation 2

  • parameters okay and so/so
  • porportion
  • excluded TC_geol_desf

f2 <- lrm(risk ~ angle + building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + drainage + TC_mature_Soil + density + TC + tree +ground_veg + deforestation + banana , data=train.data, x=TRUE , y=TRUE)

      stargazer(anova(f2), type="text", style="default")
eq_OLR_02 <- polr(risk ~ brick+ wood+ EN+  TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,
                  
                 data= train.data
           ,  method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_02))








p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                             Value Std. Error     t value      p value
## brickTRUE             -0.43428225  0.5593616 -0.77638912 2.187596e-01
## woodTRUE               1.04338525  0.3433839  3.03853867 1.188643e-03
## ENTRUE                 0.37273983  0.3754420  0.99280259 1.604031e-01
## TC_mature_soilTRUE     0.41053323  0.2347865  1.74853843 4.018542e-02
## T_constructionTRUE     0.28973309  0.3787010  0.76507091 2.221147e-01
## landfillTRUE           0.39820802  0.3322528  1.19850927 1.153594e-01
## leakTRUE              -0.57100241  0.2537036 -2.25066774 1.220329e-02
## garbageTRUE            0.25513343  0.2997366  0.85119219 1.973313e-01
## crackTRUE              1.68182586  0.3277933  5.13075137 1.442939e-07
## leaning_wallTRUE       1.56025982  0.5474243  2.85018351 2.184701e-03
## treeTRUE               0.03627160  0.2519211  0.14398001 4.427581e-01
## downward_floorTRUE     1.07810669  0.3741172  2.88173493 1.977461e-03
## tiltedTRUE             0.84540446  0.3096889  2.72985046 3.168153e-03
## ground_vegTRUE         0.69300097  0.2794987  2.47944255 6.579396e-03
## scarsTRUE              4.25531841  0.3852020 11.04697933 1.133577e-28
## mixedTRUE              1.25057841  0.5460390  2.29027304 1.100275e-02
## conc_rainfallTRUE      1.17599861  0.5896631  1.99435681 2.305654e-02
## wastewaterTRUE         0.81730759  0.2492762  3.27872279 5.213901e-04
## angleD                 0.60703651  0.4741130  1.28036264 1.002088e-01
## angleE                 0.56304223  0.5362091  1.05004232 1.468493e-01
## bananaTRUE             0.32908163  0.2557007  1.28697958 9.905070e-02
## drainage.L             0.93233807  0.2825364  3.29988604 4.836205e-04
## drainage.Q            -0.17788229  0.1915268 -0.92875938 1.765069e-01
## TC_saprolite_soilTRUE  0.15475905  0.3015818  0.51315786 3.039205e-01
## TCTRUE                -0.03809614  0.5491873 -0.06936821 4.723483e-01
## deforestationTRUE      0.06286918  0.4133030  0.15211405 4.395485e-01
## R1|R2                  0.66626825  1.1321921  0.58847630 2.781063e-01
## R2|R3                  5.28878615  1.1727555  4.50970926 3.245827e-06
## R3|R4                 10.61787605  1.2762388  8.31966224 4.410717e-17
stargazer((ctable), type="text", style="default", digits=2)
## 
## ======================================================
##                       Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE             -0.43    0.56     -0.78   0.22  
## woodTRUE              1.04     0.34     3.04    0.001 
## ENTRUE                0.37     0.38     0.99    0.16  
## TC_mature_soilTRUE    0.41     0.23     1.75    0.04  
## T_constructionTRUE    0.29     0.38     0.77    0.22  
## landfillTRUE          0.40     0.33     1.20    0.12  
## leakTRUE              -0.57    0.25     -2.25   0.01  
## garbageTRUE           0.26     0.30     0.85    0.20  
## crackTRUE             1.68     0.33     5.13   0.0000 
## leaning_wallTRUE      1.56     0.55     2.85    0.002 
## treeTRUE              0.04     0.25     0.14    0.44  
## downward_floorTRUE    1.08     0.37     2.88    0.002 
## tiltedTRUE            0.85     0.31     2.73    0.003 
## ground_vegTRUE        0.69     0.28     2.48    0.01  
## scarsTRUE             4.26     0.39     11.05     0   
## mixedTRUE             1.25     0.55     2.29    0.01  
## conc_rainfallTRUE     1.18     0.59     1.99    0.02  
## wastewaterTRUE        0.82     0.25     3.28    0.001 
## angleD                0.61     0.47     1.28    0.10  
## angleE                0.56     0.54     1.05    0.15  
## bananaTRUE            0.33     0.26     1.29    0.10  
## drainage.L            0.93     0.28     3.30   0.0005 
## drainage.Q            -0.18    0.19     -0.93   0.18  
## TC_saprolite_soilTRUE 0.15     0.30     0.51    0.30  
## TCTRUE                -0.04    0.55     -0.07   0.47  
## deforestationTRUE     0.06     0.41     0.15    0.44  
## R1| R2                0.67     1.13     0.59    0.28  
## R2| R3                5.29     1.17     4.51   0.0000 
## R3| R4                10.62    1.28     8.32      0   
## ------------------------------------------------------
par(mfrow=c(6,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN+  TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation
          ,data=train.data, cr=TRUE , subn=FALSE ,  cex.lab=1.5, cex.axis=4, cex.sub=4, cex.main=4)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN+  TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,data=train.data
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +-----------------+---+---+----+----------+------------+----------+
## |                 |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +-----------------+---+---+----+----------+------------+----------+
## |brick            |No | 35|Inf | 3.5263605| 1.575536361|-0.5260931|
## |                 |Yes|494|Inf | 2.2761518|-0.097242548|-2.0771662|
## +-----------------+---+---+----+----------+------------+----------+
## |wood             |No |457|Inf | 2.2392580|-0.153473402|-2.2143609|
## |                 |Yes| 72|Inf | 3.1354942| 1.025852934|-0.7563261|
## +-----------------+---+---+----+----------+------------+----------+
## |EN               |No |345|Inf | 1.9229206|-0.417557154|-2.3884464|
## |                 |Yes|184|Inf | 4.0998847| 0.801135819|-1.3131721|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_mature_soil   |No |244|Inf | 1.8908504|-0.263814591|-2.2155737|
## |                 |Yes|285|Inf | 2.8903718| 0.218407947|-1.7006073|
## +-----------------+---+---+----+----------+------------+----------+
## |T_construction   |No |197|Inf | 1.4978854|-0.999521386|-4.1692459|
## |                 |Yes|332|Inf | 3.3735459| 0.556067588|-1.4128614|
## +-----------------+---+---+----+----------+------------+----------+
## |landfill         |No |325|Inf | 1.8281271|-0.522329448|-2.8364760|
## |                 |Yes|204|Inf | 4.6151205| 0.851970766|-1.1249296|
## +-----------------+---+---+----+----------+------------+----------+
## |leak             |No |347|Inf | 1.9826422|-0.296092551|-2.4329866|
## |                 |Yes|182|Inf | 3.5667118| 0.563935449|-1.2669476|
## +-----------------+---+---+----+----------+------------+----------+
## |garbage          |No |332|Inf | 2.0166110|-0.328216256|-2.5978471|
## |                 |Yes|197|Inf | 3.1623055| 0.551647618|-1.2172180|
## +-----------------+---+---+----+----------+------------+----------+
## |crack            |No |438|Inf | 2.1671471|-0.350579054|-2.7227563|
## |                 |Yes| 91|Inf | 3.7954892| 2.339399066|-0.1984509|
## +-----------------+---+---+----+----------+------------+----------+
## |leaning_wall     |No |502|Inf | 2.2701498|-0.087705580|-2.1367310|
## |                 |Yes| 27|Inf |       Inf| 2.079441542| 0.2231436|
## +-----------------+---+---+----+----------+------------+----------+
## |tree             |No |214|Inf | 1.6320377|-0.679160939|-2.3285606|
## |                 |Yes|315|Inf | 3.2288262| 0.445311017|-1.6916760|
## +-----------------+---+---+----+----------+------------+----------+
## |downward_floor   |No |469|Inf | 2.1948577|-0.244277863|-2.2187308|
## |                 |Yes| 60|Inf |       Inf| 3.367295830|-0.5465437|
## +-----------------+---+---+----+----------+------------+----------+
## |tilted           |No |428|Inf | 2.1167792|-0.417161148|-2.3877429|
## |                 |Yes|101|Inf | 4.6051702| 2.597384633|-0.7683706|
## +-----------------+---+---+----+----------+------------+----------+
## |ground_veg       |No |163|Inf | 1.3710269|-1.371026889|-2.8397280|
## |                 |Yes|366|Inf | 3.2245738| 0.537142932|-1.6493103|
## +-----------------+---+---+----+----------+------------+----------+
## |scars            |No |320|Inf | 1.7844867|-1.445954198|-4.3694479|
## |                 |Yes|209|Inf | 5.3375381| 3.521446510|-0.8178507|
## +-----------------+---+---+----+----------+------------+----------+
## |mixed            |No |488|Inf | 2.2626685|-0.073803975|-2.0634045|
## |                 |Yes| 41|Inf | 3.6888795| 0.882389180|-0.7672552|
## +-----------------+---+---+----+----------+------------+----------+
## |conc_rainfall    |No | 17|Inf |-0.3566749|-2.772588722|      -Inf|
## |                 |Yes|512|Inf | 2.5523969| 0.054701136|-1.8763169|
## +-----------------+---+---+----+----------+------------+----------+
## |wastewater       |No |210|Inf | 1.6094379|-0.465363250|-2.8954096|
## |                 |Yes|319|Inf | 3.2419411| 0.296831267|-1.5252932|
## +-----------------+---+---+----+----------+------------+----------+
## |angle            |C  | 34|Inf |       Inf|-0.356674944|-3.4965076|
## |                 |D  |120|Inf | 3.3672958| 0.927986772|-1.1895841|
## |                 |E  |375|Inf | 2.0439349|-0.251991706|-2.1535495|
## +-----------------+---+---+----+----------+------------+----------+
## |banana           |No |358|Inf | 1.9395407|-0.372979653|-2.2543830|
## |                 |Yes|171|Inf | 4.4367515| 0.800392711|-1.3936204|
## +-----------------+---+---+----+----------+------------+----------+
## |drainage         |Y  | 66|Inf | 0.6931472|-1.609437912|-3.4657359|
## |                 |P  |234|Inf | 2.3167697|-0.561295049|-2.4849066|
## |                 |N  |229|Inf | 4.0298060| 1.013090115|-1.3272960|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_saprolite_soil|No |444|Inf | 2.2072749|-0.099180320|-2.0419840|
## |                 |Yes| 85|Inf | 3.3081070| 0.504556011|-1.3862944|
## +-----------------+---+---+----+----------+------------+----------+
## |TC               |No | 25|Inf |       Inf| 0.753771802|-0.9444616|
## |                 |Yes|504|Inf | 2.2745358|-0.039687748|-1.9826959|
## +-----------------+---+---+----+----------+------------+----------+
## |deforestation    |No |491|Inf | 2.3956755| 0.061118815|-1.8800521|
## |                 |Yes| 38|Inf | 1.6739764|-0.897941593|-2.4567358|
## +-----------------+---+---+----+----------+------------+----------+
## |Overall          |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +-----------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=2, cex.sub=1)

Equation 3

  • parameters okay and so/so
  • porportion
  • p-value based equation 2 > 0.5

f3 <- lrm(risk ~ angle +building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ tree + TC , data=train.data, x=TRUE , y=TRUE) stargazer(anova(f3), type=“text”, style=“default”)

# x=TRUE, y=TRUE used by resid() below 

eq_OLR_03 <- polr(risk ~ wood+  TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, data=train.data
           ,  method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_03))


p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                          Value Std. Error     t value      p value
## woodTRUE            0.92006523  0.3197546  2.87741061 2.004767e-03
## TC_mature_soilTRUE  0.45476338  0.2233160  2.03641183 2.085451e-02
## T_constructionTRUE  0.50821156  0.3044479  1.66928933 4.753003e-02
## landfillTRUE        0.23117883  0.2942678  0.78560699 2.160489e-01
## crackTRUE           1.77452208  0.3160897  5.61398266 9.886102e-09
## leaning_wallTRUE    1.60809991  0.5337990  3.01255707 1.295284e-03
## treeTRUE            0.01050506  0.2421647  0.04337981 4.826994e-01
## downward_floorTRUE  0.99400266  0.3562622  2.79008705 2.634694e-03
## tiltedTRUE          0.89463608  0.3059645  2.92398606 1.727901e-03
## ground_vegTRUE      0.67421846  0.2709742  2.48812827 6.420870e-03
## scarsTRUE           4.08532113  0.3755368 10.87861752 7.287838e-28
## conc_rainfallTRUE   1.13427719  0.5786522  1.96020527 2.498590e-02
## wastewaterTRUE      0.81342603  0.2408353  3.37752024 3.657129e-04
## bananaTRUE          0.40211950  0.2449944  1.64134146 5.036328e-02
## drainage.L          0.92255583  0.2762185  3.33994886 4.189691e-04
## drainage.Q         -0.15615152  0.1872207 -0.83405033 2.021263e-01
## R1|R2               0.56123565  0.5638092  0.99543544 1.597623e-01
## R2|R3               5.04303382  0.6305953  7.99725900 6.360972e-16
## R3|R4              10.21538351  0.7847474 13.01741689 4.870535e-39
stargazer((ctable), type="text", style="default", digits = 2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE           0.92     0.32     2.88    0.002 
## TC_mature_soilTRUE 0.45     0.22     2.04    0.02  
## T_constructionTRUE 0.51     0.30     1.67    0.05  
## landfillTRUE       0.23     0.29     0.79    0.22  
## crackTRUE          1.77     0.32     5.61      0   
## leaning_wallTRUE   1.61     0.53     3.01    0.001 
## treeTRUE           0.01     0.24     0.04    0.48  
## downward_floorTRUE 0.99     0.36     2.79    0.003 
## tiltedTRUE         0.89     0.31     2.92    0.002 
## ground_vegTRUE     0.67     0.27     2.49    0.01  
## scarsTRUE          4.09     0.38     10.88     0   
## conc_rainfallTRUE  1.13     0.58     1.96    0.02  
## wastewaterTRUE     0.81     0.24     3.38   0.0004 
## bananaTRUE         0.40     0.24     1.64    0.05  
## drainage.L         0.92     0.28     3.34   0.0004 
## drainage.Q         -0.16    0.19     -0.83   0.20  
## R1| R2             0.56     0.56     1.00    0.16  
## R2| R3             5.04     0.63     8.00      0   
## R3| R4             10.22    0.78     13.02     0   
## ---------------------------------------------------
#print (f3 , latex =TRUE , coefs =5)
par(mfrow=c(3,5))
plot.xmean.ordinaly (risk ~  wood+  TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage,,
          data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~wood+  TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +--------------+---+---+----+----------+------------+----------+
## |wood          |No |457|Inf | 2.2392580|-0.153473402|-2.2143609|
## |              |Yes| 72|Inf | 3.1354942| 1.025852934|-0.7563261|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |244|Inf | 1.8908504|-0.263814591|-2.2155737|
## |              |Yes|285|Inf | 2.8903718| 0.218407947|-1.7006073|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |197|Inf | 1.4978854|-0.999521386|-4.1692459|
## |              |Yes|332|Inf | 3.3735459| 0.556067588|-1.4128614|
## +--------------+---+---+----+----------+------------+----------+
## |landfill      |No |325|Inf | 1.8281271|-0.522329448|-2.8364760|
## |              |Yes|204|Inf | 4.6151205| 0.851970766|-1.1249296|
## +--------------+---+---+----+----------+------------+----------+
## |crack         |No |438|Inf | 2.1671471|-0.350579054|-2.7227563|
## |              |Yes| 91|Inf | 3.7954892| 2.339399066|-0.1984509|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall  |No |502|Inf | 2.2701498|-0.087705580|-2.1367310|
## |              |Yes| 27|Inf |       Inf| 2.079441542| 0.2231436|
## +--------------+---+---+----+----------+------------+----------+
## |tree          |No |214|Inf | 1.6320377|-0.679160939|-2.3285606|
## |              |Yes|315|Inf | 3.2288262| 0.445311017|-1.6916760|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |469|Inf | 2.1948577|-0.244277863|-2.2187308|
## |              |Yes| 60|Inf |       Inf| 3.367295830|-0.5465437|
## +--------------+---+---+----+----------+------------+----------+
## |tilted        |No |428|Inf | 2.1167792|-0.417161148|-2.3877429|
## |              |Yes|101|Inf | 4.6051702| 2.597384633|-0.7683706|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg    |No |163|Inf | 1.3710269|-1.371026889|-2.8397280|
## |              |Yes|366|Inf | 3.2245738| 0.537142932|-1.6493103|
## +--------------+---+---+----+----------+------------+----------+
## |scars         |No |320|Inf | 1.7844867|-1.445954198|-4.3694479|
## |              |Yes|209|Inf | 5.3375381| 3.521446510|-0.8178507|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.3566749|-2.772588722|      -Inf|
## |              |Yes|512|Inf | 2.5523969| 0.054701136|-1.8763169|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater    |No |210|Inf | 1.6094379|-0.465363250|-2.8954096|
## |              |Yes|319|Inf | 3.2419411| 0.296831267|-1.5252932|
## +--------------+---+---+----+----------+------------+----------+
## |banana        |No |358|Inf | 1.9395407|-0.372979653|-2.2543830|
## |              |Yes|171|Inf | 4.4367515| 0.800392711|-1.3936204|
## +--------------+---+---+----+----------+------------+----------+
## |drainage      |Y  | 66|Inf | 0.6931472|-1.609437912|-3.4657359|
## |              |P  |234|Inf | 2.3167697|-0.561295049|-2.4849066|
## |              |N  |229|Inf | 4.0298060| 1.013090115|-1.3272960|
## +--------------+---+---+----+----------+------------+----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.6, cex.axis=0.6, cex.sub=0.6)

Equation 4

  • p-value equation 3 > 0.05 (banana, DepTaludeCorte)
  • consider proportion
  • paremeters okay & so/so
  • fashion order

f4 <- lrm(risk ~ building + EN
+ DepEncNatural
+ crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + drainage + TC_mature_Soil + TC + +ground_veg
,data=train.data, x=TRUE , y=TRUE) # x=TRUE, y=TRUE used by resid() below #print (f4 , latex =TRUE , coefs =5) stargazer(anova(f4), type=“text”, style=“default”)

eq_OLR_04 <- polr(risk~ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
                  , data= train.data
           ,  method = "logistic", Hess = TRUE)
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value

ctable <- coef(summary(eq_OLR_04))

ctable <- cbind(ctable, "p value" = p )
## Warning in cbind(ctable, `p value` = p): number of rows of result is not a
## multiple of vector length (arg 2)
ctable
##                           Value Std. Error    t value      p value
## woodTRUE            0.921222085  0.3191972  2.8860593 2.004767e-03
## TC_mature_soilTRUE  0.428153341  0.2205185  1.9415758 2.085451e-02
## T_constructionTRUE  0.647898991  0.2473875  2.6189644 4.753003e-02
## crackTRUE           1.807450123  0.3138113  5.7596724 2.160489e-01
## leaning_wallTRUE    1.581723953  0.5348641  2.9572444 9.886102e-09
## treeTRUE           -0.006649604  0.2409958 -0.0275922 1.295284e-03
## downward_floorTRUE  1.023142282  0.3537082  2.8926165 4.826994e-01
## tiltedTRUE          0.940526352  0.3004566  3.1303238 2.634694e-03
## ground_vegTRUE      0.698257501  0.2689098  2.5966231 1.727901e-03
## scarsTRUE           4.079253951  0.3755660 10.8616156 6.420870e-03
## conc_rainfallTRUE   1.154871595  0.5785593  1.9961163 7.287838e-28
## wastewaterTRUE      0.777188288  0.2363234  3.2886642 2.498590e-02
## bananaTRUE          0.403632707  0.2448098  1.6487603 3.657129e-04
## drainage.L          0.929176173  0.2757864  3.3691884 5.036328e-02
## drainage.Q         -0.146797771  0.1866843 -0.7863422 4.189691e-04
## R1|R2               0.564567379  0.5644160  1.0002681 2.021263e-01
## R2|R3               5.048387656  0.6313539  7.9961302 1.597623e-01
## R3|R4              10.213125790  0.7854888 13.0022555 6.360972e-16
stargazer((ctable), type="text", style="default", digits=2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE           0.92     0.32     2.89    0.002 
## TC_mature_soilTRUE 0.43     0.22     1.94    0.02  
## T_constructionTRUE 0.65     0.25     2.62    0.05  
## crackTRUE          1.81     0.31     5.76    0.22  
## leaning_wallTRUE   1.58     0.53     2.96      0   
## treeTRUE           -0.01    0.24     -0.03   0.001 
## downward_floorTRUE 1.02     0.35     2.89    0.48  
## tiltedTRUE         0.94     0.30     3.13    0.003 
## ground_vegTRUE     0.70     0.27     2.60    0.002 
## scarsTRUE          4.08     0.38     10.86   0.01  
## conc_rainfallTRUE  1.15     0.58     2.00      0   
## wastewaterTRUE     0.78     0.24     3.29    0.02  
## bananaTRUE         0.40     0.24     1.65   0.0004 
## drainage.L         0.93     0.28     3.37    0.05  
## drainage.Q         -0.15    0.19     -0.79  0.0004 
## R1| R2             0.56     0.56     1.00    0.20  
## R2| R3             5.05     0.63     8.00    0.16  
## R3| R4             10.21    0.79     13.00     0   
## ---------------------------------------------------
par(mfrow=c(4,4))
plot.xmean.ordinaly (risk ~  wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
          ,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +--------------+---+---+----+----------+------------+----------+
## |wood          |No |457|Inf | 2.2392580|-0.153473402|-2.2143609|
## |              |Yes| 72|Inf | 3.1354942| 1.025852934|-0.7563261|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |244|Inf | 1.8908504|-0.263814591|-2.2155737|
## |              |Yes|285|Inf | 2.8903718| 0.218407947|-1.7006073|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |197|Inf | 1.4978854|-0.999521386|-4.1692459|
## |              |Yes|332|Inf | 3.3735459| 0.556067588|-1.4128614|
## +--------------+---+---+----+----------+------------+----------+
## |crack         |No |438|Inf | 2.1671471|-0.350579054|-2.7227563|
## |              |Yes| 91|Inf | 3.7954892| 2.339399066|-0.1984509|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall  |No |502|Inf | 2.2701498|-0.087705580|-2.1367310|
## |              |Yes| 27|Inf |       Inf| 2.079441542| 0.2231436|
## +--------------+---+---+----+----------+------------+----------+
## |tree          |No |214|Inf | 1.6320377|-0.679160939|-2.3285606|
## |              |Yes|315|Inf | 3.2288262| 0.445311017|-1.6916760|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |469|Inf | 2.1948577|-0.244277863|-2.2187308|
## |              |Yes| 60|Inf |       Inf| 3.367295830|-0.5465437|
## +--------------+---+---+----+----------+------------+----------+
## |tilted        |No |428|Inf | 2.1167792|-0.417161148|-2.3877429|
## |              |Yes|101|Inf | 4.6051702| 2.597384633|-0.7683706|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg    |No |163|Inf | 1.3710269|-1.371026889|-2.8397280|
## |              |Yes|366|Inf | 3.2245738| 0.537142932|-1.6493103|
## +--------------+---+---+----+----------+------------+----------+
## |scars         |No |320|Inf | 1.7844867|-1.445954198|-4.3694479|
## |              |Yes|209|Inf | 5.3375381| 3.521446510|-0.8178507|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.3566749|-2.772588722|      -Inf|
## |              |Yes|512|Inf | 2.5523969| 0.054701136|-1.8763169|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater    |No |210|Inf | 1.6094379|-0.465363250|-2.8954096|
## |              |Yes|319|Inf | 3.2419411| 0.296831267|-1.5252932|
## +--------------+---+---+----+----------+------------+----------+
## |banana        |No |358|Inf | 1.9395407|-0.372979653|-2.2543830|
## |              |Yes|171|Inf | 4.4367515| 0.800392711|-1.3936204|
## +--------------+---+---+----+----------+------------+----------+
## |drainage      |Y  | 66|Inf | 0.6931472|-1.609437912|-3.4657359|
## |              |P  |234|Inf | 2.3167697|-0.561295049|-2.4849066|
## |              |N  |229|Inf | 4.0298060| 1.013090115|-1.3272960|
## +--------------+---+---+----+----------+------------+----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)

Equation 5 - Based on Equation 1

  • based on Eq 1
  • less p-value > 0.10 (
# x=TRUE, y=TRUE used by resid() below 
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")

eq_OLR_05 <- polr(risk ~ brick+ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg,  data= train.data
           ,  method = "logistic", Hess = TRUE)

ctable <- coef(summary(eq_OLR_05))

p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                         Value Std. Error    t value      p value
## brickTRUE          -0.9677011  0.4453529 -2.1728862 1.489444e-02
## woodTRUE            0.9704591  0.3200049  3.0326383 1.212130e-03
## TC_mature_soilTRUE  0.4772300  0.2167449  2.2018051 1.383954e-02
## T_constructionTRUE  0.7131302  0.2431542  2.9328319 1.679429e-03
## crackTRUE           1.7828386  0.3119006  5.7160474 5.451518e-09
## leaning_wallTRUE    1.5082465  0.5321385  2.8343119 2.296224e-03
## scarsTRUE           4.1687751  0.3758985 11.0901606 7.001804e-29
## downward_floorTRUE  1.0886868  0.3589116  3.0333005 1.209473e-03
## tiltedTRUE          1.0468586  0.3022256  3.4638314 2.662701e-04
## conc_rainfallTRUE   1.6315823  0.5489943  2.9719474 1.479587e-03
## wastewaterTRUE      0.8695603  0.2328380  3.7346150 9.400128e-05
## ground_vegTRUE      0.9239225  0.2438946  3.7882043 7.587004e-05
## R1|R2               0.2211011  0.6945791  0.3183239 3.751196e-01
## R2|R3               4.5360526  0.7547378  6.0101036 9.270241e-10
## R3|R4               9.7274016  0.8723667 11.1505879 3.556742e-29
stargazer((ctable), type="text", style="default", digits = 2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE          -0.97    0.45     -2.17   0.01  
## woodTRUE           0.97     0.32     3.03    0.001 
## TC_mature_soilTRUE 0.48     0.22     2.20    0.01  
## T_constructionTRUE 0.71     0.24     2.93    0.002 
## crackTRUE          1.78     0.31     5.72      0   
## leaning_wallTRUE   1.51     0.53     2.83    0.002 
## scarsTRUE          4.17     0.38     11.09     0   
## downward_floorTRUE 1.09     0.36     3.03    0.001 
## tiltedTRUE         1.05     0.30     3.46   0.0003 
## conc_rainfallTRUE  1.63     0.55     2.97    0.001 
## wastewaterTRUE     0.87     0.23     3.73   0.0001 
## ground_vegTRUE     0.92     0.24     3.79   0.0001 
## R1| R2             0.22     0.69     0.32    0.38  
## R2| R3             4.54     0.75     6.01      0   
## R3| R4             9.73     0.87     11.15     0   
## ---------------------------------------------------
par(mfrow=c(3,4))
plot.xmean.ordinaly (risk ~  brick+ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
          ,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +--------------+---+---+----+----------+------------+----------+
## |brick         |No | 35|Inf | 3.5263605| 1.575536361|-0.5260931|
## |              |Yes|494|Inf | 2.2761518|-0.097242548|-2.0771662|
## +--------------+---+---+----+----------+------------+----------+
## |wood          |No |457|Inf | 2.2392580|-0.153473402|-2.2143609|
## |              |Yes| 72|Inf | 3.1354942| 1.025852934|-0.7563261|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |244|Inf | 1.8908504|-0.263814591|-2.2155737|
## |              |Yes|285|Inf | 2.8903718| 0.218407947|-1.7006073|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |197|Inf | 1.4978854|-0.999521386|-4.1692459|
## |              |Yes|332|Inf | 3.3735459| 0.556067588|-1.4128614|
## +--------------+---+---+----+----------+------------+----------+
## |crack         |No |438|Inf | 2.1671471|-0.350579054|-2.7227563|
## |              |Yes| 91|Inf | 3.7954892| 2.339399066|-0.1984509|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall  |No |502|Inf | 2.2701498|-0.087705580|-2.1367310|
## |              |Yes| 27|Inf |       Inf| 2.079441542| 0.2231436|
## +--------------+---+---+----+----------+------------+----------+
## |scars         |No |320|Inf | 1.7844867|-1.445954198|-4.3694479|
## |              |Yes|209|Inf | 5.3375381| 3.521446510|-0.8178507|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |469|Inf | 2.1948577|-0.244277863|-2.2187308|
## |              |Yes| 60|Inf |       Inf| 3.367295830|-0.5465437|
## +--------------+---+---+----+----------+------------+----------+
## |tilted        |No |428|Inf | 2.1167792|-0.417161148|-2.3877429|
## |              |Yes|101|Inf | 4.6051702| 2.597384633|-0.7683706|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.3566749|-2.772588722|      -Inf|
## |              |Yes|512|Inf | 2.5523969| 0.054701136|-1.8763169|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater    |No |210|Inf | 1.6094379|-0.465363250|-2.8954096|
## |              |Yes|319|Inf | 3.2419411| 0.296831267|-1.5252932|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg    |No |163|Inf | 1.3710269|-1.371026889|-2.8397280|
## |              |Yes|366|Inf | 3.2245738| 0.537142932|-1.6493103|
## +--------------+---+---+----+----------+------------+----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)

OLR Equation 6

# x=TRUE, y=TRUE used by resid() below 
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")

eq_OLR_06 <- polr(risk ~ brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana,  data= train.data
           ,  method = "logistic", Hess = TRUE)

ctable <- coef(summary(eq_OLR_06))

p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                         Value Std. Error    t value      p value
## brickTRUE          -0.5569510  0.5614827 -0.9919289 1.606161e-01
## woodTRUE            1.0447383  0.3295202  3.1704833 7.609278e-04
## mixedTRUE           1.3828298  0.5386066  2.5674206 5.122913e-03
## ENTRUE              0.4487755  0.3679583  1.2196368 1.113013e-01
## TCTRUE              0.2091751  0.5128117  0.4078985 3.416741e-01
## T_constructionTRUE  0.3348989  0.3633389  0.9217260 1.783358e-01
## landfillTRUE        0.4388227  0.3203354  1.3698853 8.536136e-02
## leakTRUE           -0.3058842  0.2409840 -1.2693134 1.021647e-01
## garbageTRUE         0.2263916  0.2903523  0.7797136 2.177798e-01
## crackTRUE           1.6181105  0.3213096  5.0359857 2.376981e-07
## leaning_wallTRUE    1.6621309  0.5554303  2.9925103 1.383467e-03
## treeTRUE            0.1005813  0.2430887  0.4137636 3.395236e-01
## tiltedTRUE          1.0306191  0.3044894  3.3847453 3.562216e-04
## angleD              0.7516338  0.4634524  1.6218145 5.242153e-02
## angleE              0.7410218  0.5235041  1.4155034 7.846048e-02
## ground_vegTRUE      0.8095937  0.2703781  2.9943018 1.375368e-03
## scarsTRUE           4.3254013  0.3832016 11.2875330 7.561079e-30
## conc_rainfallTRUE   1.8157617  0.5561365  3.2649568 5.474039e-04
## wastewaterTRUE      0.8607088  0.2387776  3.6046466 1.562890e-04
## bananaTRUE          0.4112325  0.2495966  1.6475882 4.971861e-02
## R1|R2               1.5769252  1.0892900  1.4476634 7.385561e-02
## R2|R3               5.9303038  1.1436474  5.1854301 1.077584e-07
## R3|R4              11.1837127  1.2529802  8.9256902 2.214642e-19
stargazer((ctable), type="text", style="default", digits = 2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE          -0.56    0.56     -0.99   0.16  
## woodTRUE           1.04     0.33     3.17    0.001 
## mixedTRUE          1.38     0.54     2.57    0.01  
## ENTRUE             0.45     0.37     1.22    0.11  
## TCTRUE             0.21     0.51     0.41    0.34  
## T_constructionTRUE 0.33     0.36     0.92    0.18  
## landfillTRUE       0.44     0.32     1.37    0.09  
## leakTRUE           -0.31    0.24     -1.27   0.10  
## garbageTRUE        0.23     0.29     0.78    0.22  
## crackTRUE          1.62     0.32     5.04   0.0000 
## leaning_wallTRUE   1.66     0.56     2.99    0.001 
## treeTRUE           0.10     0.24     0.41    0.34  
## tiltedTRUE         1.03     0.30     3.38   0.0004 
## angleD             0.75     0.46     1.62    0.05  
## angleE             0.74     0.52     1.42    0.08  
## ground_vegTRUE     0.81     0.27     2.99    0.001 
## scarsTRUE          4.33     0.38     11.29     0   
## conc_rainfallTRUE  1.82     0.56     3.26    0.001 
## wastewaterTRUE     0.86     0.24     3.60   0.0002 
## bananaTRUE         0.41     0.25     1.65    0.05  
## R1| R2             1.58     1.09     1.45    0.07  
## R2| R3             5.93     1.14     5.19   0.0000 
## R3| R4             11.18    1.25     8.93      0   
## ---------------------------------------------------
par(mfrow=c(5,4))
plot.xmean.ordinaly (risk ~  brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
          ,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +--------------+---+---+----+----------+------------+----------+
## |brick         |No | 35|Inf | 3.5263605| 1.575536361|-0.5260931|
## |              |Yes|494|Inf | 2.2761518|-0.097242548|-2.0771662|
## +--------------+---+---+----+----------+------------+----------+
## |wood          |No |457|Inf | 2.2392580|-0.153473402|-2.2143609|
## |              |Yes| 72|Inf | 3.1354942| 1.025852934|-0.7563261|
## +--------------+---+---+----+----------+------------+----------+
## |mixed         |No |488|Inf | 2.2626685|-0.073803975|-2.0634045|
## |              |Yes| 41|Inf | 3.6888795| 0.882389180|-0.7672552|
## +--------------+---+---+----+----------+------------+----------+
## |EN            |No |345|Inf | 1.9229206|-0.417557154|-2.3884464|
## |              |Yes|184|Inf | 4.0998847| 0.801135819|-1.3131721|
## +--------------+---+---+----+----------+------------+----------+
## |TC            |No | 25|Inf |       Inf| 0.753771802|-0.9444616|
## |              |Yes|504|Inf | 2.2745358|-0.039687748|-1.9826959|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |197|Inf | 1.4978854|-0.999521386|-4.1692459|
## |              |Yes|332|Inf | 3.3735459| 0.556067588|-1.4128614|
## +--------------+---+---+----+----------+------------+----------+
## |landfill      |No |325|Inf | 1.8281271|-0.522329448|-2.8364760|
## |              |Yes|204|Inf | 4.6151205| 0.851970766|-1.1249296|
## +--------------+---+---+----+----------+------------+----------+
## |leak          |No |347|Inf | 1.9826422|-0.296092551|-2.4329866|
## |              |Yes|182|Inf | 3.5667118| 0.563935449|-1.2669476|
## +--------------+---+---+----+----------+------------+----------+
## |garbage       |No |332|Inf | 2.0166110|-0.328216256|-2.5978471|
## |              |Yes|197|Inf | 3.1623055| 0.551647618|-1.2172180|
## +--------------+---+---+----+----------+------------+----------+
## |crack         |No |438|Inf | 2.1671471|-0.350579054|-2.7227563|
## |              |Yes| 91|Inf | 3.7954892| 2.339399066|-0.1984509|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall  |No |502|Inf | 2.2701498|-0.087705580|-2.1367310|
## |              |Yes| 27|Inf |       Inf| 2.079441542| 0.2231436|
## +--------------+---+---+----+----------+------------+----------+
## |tree          |No |214|Inf | 1.6320377|-0.679160939|-2.3285606|
## |              |Yes|315|Inf | 3.2288262| 0.445311017|-1.6916760|
## +--------------+---+---+----+----------+------------+----------+
## |tilted        |No |428|Inf | 2.1167792|-0.417161148|-2.3877429|
## |              |Yes|101|Inf | 4.6051702| 2.597384633|-0.7683706|
## +--------------+---+---+----+----------+------------+----------+
## |angle         |C  | 34|Inf |       Inf|-0.356674944|-3.4965076|
## |              |D  |120|Inf | 3.3672958| 0.927986772|-1.1895841|
## |              |E  |375|Inf | 2.0439349|-0.251991706|-2.1535495|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg    |No |163|Inf | 1.3710269|-1.371026889|-2.8397280|
## |              |Yes|366|Inf | 3.2245738| 0.537142932|-1.6493103|
## +--------------+---+---+----+----------+------------+----------+
## |scars         |No |320|Inf | 1.7844867|-1.445954198|-4.3694479|
## |              |Yes|209|Inf | 5.3375381| 3.521446510|-0.8178507|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 17|Inf |-0.3566749|-2.772588722|      -Inf|
## |              |Yes|512|Inf | 2.5523969| 0.054701136|-1.8763169|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater    |No |210|Inf | 1.6094379|-0.465363250|-2.8954096|
## |              |Yes|319|Inf | 3.2419411| 0.296831267|-1.5252932|
## +--------------+---+---+----+----------+------------+----------+
## |banana        |No |358|Inf | 1.9395407|-0.372979653|-2.2543830|
## |              |Yes|171|Inf | 4.4367515| 0.800392711|-1.3936204|
## +--------------+---+---+----+----------+------------+----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)

Predicion on test data Eq 1: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel1 <- predict(eq_OLR_01, test.data) # predict the levels directly

predictedScores1 <- predict(eq_OLR_01, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel1)
##     predictedLevel1
##      R1 R2 R3 R4
##   R1  4 15  0  0
##   R2  3 83  7  0
##   R3  0 21 55  8
##   R4  0  1 13 14
p1 <- mean(as.character(test.data$risk) != as.character(predictedLevel1)) #misclassification error
p1 
## [1] 0.3035714

Predicion on test data Eq 2: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel2 <- predict(eq_OLR_02, test.data) # predict the levels directly

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel2)
##     predictedLevel2
##      R1 R2 R3 R4
##   R1  4 15  0  0
##   R2  5 81  7  0
##   R3  0 22 52 10
##   R4  0  1 13 14
p2 <- mean(as.character(test.data$risk) != as.character(predictedLevel2))
p2
## [1] 0.3258929

Predicion on test data Eq 3: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel3 <- predict(eq_OLR_03, test.data) # predict the levels directly

predictedScores1 <- predict(eq_OLR_03, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel3)
##     predictedLevel3
##      R1 R2 R3 R4
##   R1  4 15  0  0
##   R2  5 82  6  0
##   R3  0 23 52  9
##   R4  0  1 14 13
p3 <- mean(as.character(test.data$risk) != as.character(predictedLevel3))
p3
## [1] 0.3258929

Predicion on test data Eq 4: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel4 <- predict(eq_OLR_04, test.data) # predict the levels directly

predictedScores1 <- predict(eq_OLR_04, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel4)
##     predictedLevel4
##      R1 R2 R3 R4
##   R1  4 15  0  0
##   R2  5 82  6  0
##   R3  0 23 52  9
##   R4  0  1 14 13
p4 <- mean(as.character(test.data$risk) != as.character(predictedLevel4))
p4
## [1] 0.3258929

Predicion on test data Eq 5: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel5 <- predict(eq_OLR_05, test.data) # predict the levels directly

predictedScores5 <- predict(eq_OLR_05, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel5)
##     predictedLevel5
##      R1 R2 R3 R4
##   R1  4 15  0  0
##   R2  2 84  7  0
##   R3  0 20 56  8
##   R4  0  1 13 14
p5 <- mean(as.character(test.data$risk) != as.character(predictedLevel5))
p5
## [1] 0.2946429

Predicion on test data Eq 6: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel6 <- predict(eq_OLR_06, test.data) # predict the levels directly

predictedScores6 <- predict(eq_OLR_06, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel6)
##     predictedLevel6
##      R1 R2 R3 R4
##   R1  4 15  0  0
##   R2  0 86  7  0
##   R3  0 21 54  9
##   R4  0  1 15 12
p6 <- mean(as.character(test.data$risk) != as.character(predictedLevel6))
p6
## [1] 0.3035714

Predicion on test data Eq 7: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

#Table 

df2 <- data.frame(
  
  "Equations"=c(1:6), 
  "Predicted"=c(1-p1, 
                1-p2,
                1-p3,
                1-p4,
                1-p5,
                1-p6
               
              
    
    
  )
  
  
  
)

df2
##   Equations Predicted
## 1         1 0.6964286
## 2         2 0.6741071
## 3         3 0.6741071
## 4         4 0.6741071
## 5         5 0.7053571
## 6         6 0.6964286